import { optionSelect } from '@/api/modules/system/dict/dict';
import { fetchCodeById } from '@/api/modules/tool/gen/gen';
import { genInterface } from '../../../data/table';
import { codeFormData } from './data';

/**
 * @description: 获取表单信息
 * @param {number} code
 */
export const getTableInfo = async (code: number): Promise<CodeResponse | undefined> => {
  const { data } = await fetchCodeById(code);
  if (data.data) {
    codeFormData.value = data.data;
    return data.data;
  }
};

/* 字典类型转下拉框数据 */
const dictToOptions = (dict: SystemDict[]) => {
  return dict.map(e => {
    return {
      label: e.dictName,
      value: e.dictType,
    };
  });
};

export const getDictOptions = async (options: Ref) => {
  const { data } = await optionSelect();
  if (data.data) {
    options.value = dictToOptions(data.data);
  }
};
export const goGenHome = () => {
  genInterface.value = 'DB_TABLE';
};
